package com.nova.base.response;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * 响应
 *
 * @author ttao
 * @since 2024/9/29 22:53
 */
@Setter
@Getter
public class Response<T> extends BaseResponse {
    private static final long serialVersionUID = 1L;

    private T data;

    public static <T> Response<T> of() {
        Response<T> response = new Response<>();
        response.setSuccess(true);
        return response;
    }


    public static <T> Response<T> of(T data) {
        Response<T> response = new Response<>();
        response.setSuccess(true);
        response.setData(data);
        return response;
    }

    public static <T> Response<T> fail() {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        return response;
    }

    public static <T> Response<T> fail(String errorMessage) {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setMessage(errorMessage);
        return response;
    }

    public static <T> Response<T> fail(String errorCode, String errorMessage) {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setCode(errorCode);
        response.setMessage(errorMessage);
        return response;
    }

    public static <T> Response<T> fail(ResponseCode responseCode, String errorMessage) {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setCode(responseCode.name());
        response.setMessage(errorMessage);
        return response;
    }

}
